package com.kgc.dubbo.controller;

import com.kgc.dubbo.service.LocalGoodsService;
import com.kgc.dubbo.vo.RespResult;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiImplicitParams;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

/**
 * 商品操作的控制器
 */
@Api(value = "商品操作的控制器")
@RestController
@RequestMapping("/api")
public class GoodsController {
    @Autowired
    private LocalGoodsService localGoodsService;
    @ApiOperation(value = "根据商品编号查询商品信息",
            httpMethod = "POST",
            protocols = "http",
            notes = "根据商品编号查询商品信息",
            produces = "application/json;charset=UTF-8",
            consumes = "application/json")
    @ApiImplicitParams({
            @ApiImplicitParam(name ="id",value = "商品编号",required = true,paramType = "form"),
            @ApiImplicitParam(name ="token",value = "token",required = true,paramType = "form")
    })
    @PostMapping(value = "v/queryGoodsById")
    public RespResult queryGoodsById(String id) throws Exception {
        RespResult respResult = localGoodsService.getGoodsById(id);
        return respResult;
    }
    @ApiOperation(value = "抢购商品的功能",
            httpMethod = "POST",
            protocols = "http",
            notes = "抢购商品的功能",
            produces = "application/json;charset=UTF-8",
            consumes = "application/json")
    @ApiImplicitParams({
            @ApiImplicitParam(name ="goodsId",value = "商品编号",required = true,paramType = "form"),
            @ApiImplicitParam(name ="token",value = "token",required = true,paramType = "form")
    })
    @PostMapping(value = "v/sendQgGoodsMessage")
    public RespResult queryGoodsById(String goodsId,String token) throws Exception {
        RespResult respResult = localGoodsService.snapupGoodsMessageSendToActiveMQ(goodsId,token);
        return respResult;
    }

    @ApiOperation(value = "处理前端轮询抢购商品结果的接口",
            httpMethod = "POST",
            protocols = "http",
            notes = "抢购商品的功能",
            produces = "application/json;charset=UTF-8",
            consumes = "application/json")
    @ApiImplicitParams({
            @ApiImplicitParam(name ="goodsId",value = "商品编号",required = true,paramType = "form"),
            @ApiImplicitParam(name ="token",value = "token",required = true,paramType = "form")
    })
    @PostMapping(value = "v/flushResult")
    public RespResult flushGoodsSnapupResult(String goodsId,String token) throws Exception {
        RespResult respResult = localGoodsService.flushGoodsSnapupResult(goodsId,token);
        return respResult;
    }

}
